/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.latticeware.xtalk.stack;

import com.latticeware.xtalk.app.ObjectFactory;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;



/**
 *
 * @author sfisque
 */
public class Button
extends VisualThing
{
    public Button( Integer _id )
    {
        super( _id, new java.awt.Button( "New Button" ) );
                
        ClickHandler _clickHandler = new ClickHandler();
        
        visualEntity.addMouseListener( _clickHandler );
        visualEntity.addMouseMotionListener( _clickHandler );
    }
    
    
    class ClickHandler
    extends MouseAdapter
    implements MouseMotionListener
    {
        Point dragLocation;
        

        @Override
        public void mouseClicked(MouseEvent e)
        {
            if( e.isShiftDown() )
            {
                Button.this.showScriptEditor();
            }
        }

        
        @Override
        public void mousePressed(MouseEvent e)
        {
            dragLocation = e.getPoint();
        }


        @Override
        public void mouseReleased(MouseEvent e)
        {
            
        }

        @Override
        public void mouseDragged( MouseEvent e )
        {
            //System.out.println( dragLocation.toString() + ":" + e.getPoint().toString() );
            Point p0 = Button.this.visualEntity.getLocation();
            Button.this.visualEntity.setLocation( p0.x + e.getX() - dragLocation.x,
                    p0.y + e.getY() - dragLocation.y );
        }
        
    }
    
}
